<?php

require_once('bibliotecas/por.php');
require_once('bibliotecas/pdf_creator.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Antônio Ezequiel');
$pdf->SetTitle('LIVRARIA EBENEZER');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');


include($configurator["classes"] . "/venda.classes.php");
include($configurator["dao"] . "/vendaDao.php");
$_venda = new VendaDao();
$venda = $_venda->listarVenda($_GET['codigo']);
$dados_loja = '<span class="nome">website: </span> '.
              '<span class="value">http://www.livrariaebenezer.com.br</span>';
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING.$venda['codigo']);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(2);

//set margins
$pdf->SetMargins(2, 30, 2);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 8, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

//include($configurator["classes"] . "/venda.classes.php");
//include($configurator["dao"] . "/vendaDao.php");
include($configurator["classes"] . "/item_venda.classes.php");
include($configurator["dao"] . "/itemVendaDao.php");

$_itemVenda = new ItemVendaDao();
$itensVenda = $_itemVenda->listarItensVenda($_GET['codigo']);
$dat = explode('-', $venda[data]);
$dat1 = explode(' ', $dat[2]);

$dados .= $dados_loja;
$dados .='
<style>
 
  table.informacao td {
     border:none;
  }
</style>
<table class="informacao" border="0" cellpadding="4" cellspacing="0">
            <tr class="tit_info_venda">
                <td></td>
                <td>Vendedor</td>
                <td>Data</td>
                <td>Cliente</td>
            </tr>
            <tr class="value_info_venda">
                <td></td>
                <td>' . $venda[usuario] . '</td>
                <td>' . $dat1[0] . '/' . $dat[1] . '/' . $dat[0] . '</td>
                <td>' . $venda[cli_nome] . '</td>
            </tr>
         </table>
    <br/>';
foreach ($itensVenda as $valor) {
    $titulo = $valor[titulo];
    $quantidade = $valor[quant];
    $preco = $valor[preco];
    $tipo = $valor[tipo];
    $editora = $valor[editora];
    $subtotal = $valor[subtotal];

    $pre = str_replace('.', ',', $preco);
    $sub = str_replace('.', ',', $subtotal);

    $dado .='<tr>
            <td>' . $titulo . '</td>
            <td>' . $tipo . '</td>
            <td>' . $editora . '</td>
            <td>' . $quantidade . '</td>
            <td>R$ ' . $pre . ',00</td>
            <td>R$ ' . $sub . ',00</td>
        </tr>';
}
$dado .='
    <tr>
        <td colspan="6"></td>
    </tr>
    <tr style="float:right; font-size:35px">
        <td style="text-align:right" width="630; font-size:35px"colspan="5">TOTAL</td>
        <td width="90" style="background-color:red;color:#ffffff">R$ ' . $venda[valor] . ',00</td>
    </tr>
    </table>';
$dados .= <<<EOF
<!-- EXAMPLE OF CSS STYLE -->
<style>   
    table {
        color: #003300;
        font-family: helvetica;
        font-size: 8pt;
        border: 1px;
        text-align: center;
        background-color: #ffffff;
    }
  
    table .cabecalho{
        font-size: 14pt;
    }
    .tit_info_venda {
        font-family:arial;
        font-weight:bold;
        background-color: #ccffcc;
        border:none;
    }
    .value_info_venda{
        font-family:arial;
        font-style:italic;
        background-color: #ffffff;
        border:none;
    }
    .tit_itens_venda{
        font-family:arial;
        font-weight:bold;
        background-color: #ccffcc;
        border:none;
    }
</style>

<table border="1" cellpadding="1" cellspacing="1">
  <tr class="tit_itens_venda" style="font-size:30px">
        <th width="350">Produto</th>
        <th width="70">Tipo</th>
        <th width="110">Editora</th>
        <th width="60">Quant</th>
        <th width="70">Preço</th>
        <th width="60">Subtotal</th>
 </tr>
 $dado
</table>
EOF;

$pdf->writeHTML($dados, true, false, true, false, '');

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('venda_recibo.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+

